import Vue from 'vue'
import ToastPlus from './index.vue'

const ToastConstructor = Vue.extend(ToastPlus)

// let instance;
let instances = []
// let seed = 1

function showToast(content, duration=1500){
  if(instances.length) return
  const ToastDOM = new ToastConstructor({
    el: document.createElement('div'),
    data(){
      return{
        content: content,
        isShow: true
      }
    }
  })

  // ToastPlus.id = 'toast_' + seed++
  instances.push(ToastPlus)

  document.body.appendChild(ToastDOM.$el)
  setTimeout(() => {
    ToastDOM.isShow = false
    instances = []
  }, duration);
}

export default function(){
  Vue.prototype.$toast = showToast
}




